package org.sean.framework.logstash.init;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;

import java.util.ArrayList;
import java.util.List;

/**
 * 初始化Kafka配置
 *
 * @author xielei
 */
@Slf4j
public class LogstashApplicationListener implements Ordered, ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    @Override
    public int getOrder() {
        return ConfigFileApplicationListener.DEFAULT_ORDER + 1;
    }

    @Autowired(required = false)
    private List<PropertySourceLocator> propertySourceLocators = new ArrayList<>();

    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        LogstashInitializer.setProperty(event.getEnvironment());
    }

}
